﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace Shoozla
{
    public class IntegerValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            String insertedValue = value as String;
            int number = 0;
            var result = Int32.TryParse(insertedValue, out number);
            return result ? ValidationResult.ValidResult : new ValidationResult(false, "Not a number"); //returning tru only if we successfully converted to Int
        }

    }

    public class YearValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            String insertedValue = value as String;
            int number = 0;
            var result = Int32.TryParse(insertedValue, out number);
            if (result)                       
                //is a number, checking if is a Year
                if (number >= 0 && number <= 9999)
                    return ValidationResult.ValidResult;
          
                
            return new ValidationResult(false, "Not a valid year");
        }

    }
}
